#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <complex>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define all(x) (x).begin(),(x).end()
typedef long long ll;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<VI> VVI;

typedef pair<int,int> PII;
typedef vector<PII> VPII;
#define X first
#define Y second
#define mp make_pair

#define two(x) (1<<(x))
#define twoll(x) ((long long)1<<(x))
#define contain(s,x) (((s)&two(x))!=0)
#define containll(s,x) (((s)&twoll(x))!=0)

#define db(a) cout << #a << "=" << a << " "
#define dbn cout << endl
template<class T> void print(vector<T> v) { cout << "["; if (v.size()) cout << v[0]; for (unsigned i = 1; i < v.size(); ++i) cout << ", " << v[i];cout << "]\n"; }
template<class T> void print(vector<vector<T> > v) { cout << "[ ---\n"; if (v.size()) cout << " ", print(v[0]); for (unsigned i = 1; i < v.size(); ++i) cout << " ", print(v[i]); cout << "--- ]\n"; }
template<class T1, class T2> void print(pair<T1, T2> p) { cout << "{" << p.first << ", " << p.second << "}"; }
template<class T1, class T2> void print(vector<pair<T1, T2> > v) { cout << "["; if (v.size()) print(v[0]); for (unsigned i = 1; i < v.size(); ++i) cout << ", ", print(v[i]);cout << "]\n"; }
#define sqr(x) (x)*(x)

template<class T> inline int chkmin(T& a, T b) { if (a>b) {a=b; return 1;} return 0; }
template<class T> inline int chkmax(T& a, T b) { if (a<b) {a=b; return 1;} return 0; }

string STR(int n) { char tmp[20]; sprintf(tmp,"%d",n); return tmp; }
int INT(string s) { return atoi(s.c_str()); }
template <class Ty, class Tx> Ty to(const Tx &x) { Ty y; stringstream ss; ss<<x; ss>>y; return y; }

const int INF = 1000000007;
const double EPS = 1e-10;

char buf[1<<20];

int CUR_CASE;
int TOTAL_CASES;

int M,N,E,sr,sc,tr,tc;
char G[505][505];
bool visit[505][505];

const int DR[] = {-1,0,1,0};	// N,E,S,W
const int DC[] = {0,1,0,-1};

struct State {
	int r,c,v;
	State(int R, int C, int V) : r(R), c(C), v(V) {}
	bool operator<(const State &s) const {
		return v < s.v;
	}
};

bool isValid(int nrow, int ncol)
{
	return nrow >= 0 && nrow < M && ncol >= 0 && ncol < N && !visit[nrow][ncol];
}

int main() {
#define SUBMIT 0
#if !SUBMIT
	freopen("DATA.in", "rt", stdin);
	freopen("DATA.ou", "wt", stdout);
	clock_t STARTTIME, ENDTIME;
	STARTTIME = clock();
#endif

	gets(buf);
	TOTAL_CASES = atoi(buf);
	
	for (CUR_CASE = 1; CUR_CASE <= TOTAL_CASES; ++CUR_CASE) {
		scanf("%d",&E);
		scanf("%d%d",&M,&N);
		for (int i = 0; i < M; ++i)
			for (int j = 0; j < N; ++j)
				scanf("%s",buf), G[i][j] = buf[0];
		for (int i = 0; i < M; ++i)
			for (int j = 0; j < N; ++j)
				if (G[i][j] == 'S')
					sr = i, sc = j;
				else if (G[i][j] == 'T')
					tr = i, tc = j;
		memset(visit,0,sizeof(visit));
		priority_queue<State> q;
		q.push(State(sr,sc,E));
		bool ok = false;
		while (!q.empty()) {
			int row = q.top().r;
			int col = q.top().c;
			int val = q.top().v;
			q.pop();
			visit[row][col] = true;
			if (G[row][col] == 'T') {
				ok = true;
				break;
			}
			for (int d = 0; d < 4; ++d) {
				int nr = row+DR[d], nc = col+DC[d];
				if (isValid(nr,nc))
					if (G[nr][nc] == '*')
					{
						if (val <= 0)
							continue;
						visit[nr][nc] = true, q.push(State(nr,nc,val-1));
					}
					else
						visit[nr][nc] = true, q.push(State(nr,nc,val));
			}
		}
		if (ok)
			printf("y\n");
		else
			printf("n\n");
	}

#if !SUBMIT
	ENDTIME = clock();
	cerr << "elapsed time : " << ENDTIME-STARTTIME << "ms";
#endif
	return 0;
}





